package com.xmut.controller;

import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.xmut.pojo.Result;
import com.xmut.pojo.Sms;
import com.xmut.pojo.Sv;
import com.xmut.service.AppointmentService;
import com.xmut.service.SmsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Random;

import static com.xmut.ali.SendMessage.sendSms;
import com.xmut.service.*;
/**
 * @author zhangbaiyan
 * @date 2024-06-15 04:31
 * @description:
 * @version:
 */
@Slf4j
@RestController
@CrossOrigin("*")
public class SmsController {
    @Autowired
    private SmsService SmsService;
    @GetMapping("/sms")
    public Result Sms() throws ClientException {
        Random random = new Random();
        int code = random.nextInt(10000)%(10000-1000) + 1000;
        System.out.println(code);
        //发短信
        SendSmsResponse response = sendSms("18157906621", String.valueOf(code));
        System.out.println("短信接口返回的数据----------------");
        System.out.println("Code=" + response.getCode());
        System.out.println("Message=" + response.getMessage());
        System.out.println("RequestId=" + response.getRequestId());
        System.out.println("BizId=" + response.getBizId());
        Sms sms=new Sms();
        sms.setCode(code);
        SmsService.add(sms);



        return Result.success();
    }
}
